<template>
	<view>
		<view class="head">
			<view class="head-left">
				<view v-if="userInfo.photo" class="figure">
					<image :src="imgUrl + userInfo.photo" mode="aspectFill">
					</image>
				</view>
				<view v-else class="figure">
					<image src="https://staticfile-yj.obs.myhuaweicloud.com/%E5%A4%B4%E5%83%8F.png" mode="aspectFill">
					</image>
				</view>
				<view class="info">
					<text class="name" v-if="userInfo.nickName">{{userInfo.nickName}}</text>
					<text class="name" v-else>暂无昵称</text>
					<!-- <view v-if="userInfo.credentialId" class="credential"> -->
					<view class="credential">
						<image src="https://staticfile-yj.obs.myhuaweicloud.com/Frame%20427318960.png" mode="widthFix">
						</image>
					</view>
				</view>
			</view>
			<view class="head-right" @click="goTo('./information/information')"><text>编辑资料</text></view>
		</view>
		<view style="padding: 0 30rpx;">
			<view class="collect">
				<view class="title">我的收藏</view>
				<view class="collect-con">
					<view class="item" @click="goTo('./favorExpert/favorExpert')">
						<text class="num">{{collectNum.experts}}</text>
						<text class="name">专家</text>
					</view>
					<view class="item" @click="goTo('./favorClass/favorClass')">
						<text class="num">{{collectNum.course}}</text>
						<text class="name">课程</text>
					</view>
					<view class="item" @click="goTo('./favorProduct/favorProduct')">
						<text class="num">{{collectNum.produce}}</text>
						<text class="name">农产品</text>
					</view>
					<view class="item" @click="goTo('./favorService/favorService')">
						<text class="num">{{collectNum.farm}}</text>
						<text class="name">农事服务</text>
					</view>
				</view>
			</view>
			<view class="mine-list">
				<view class="list-item" @click="goTo(`./myPhoto/myPhoto?credits=${credits}`)">
					<view class="left">
						<image
							src="https://staticfile-yj.obs.myhuaweicloud.com/%E6%88%91%E7%9A%84%E9%9A%8F%E6%89%8B%E6%8B%8D.png"
							mode="widthFix"></image>
						<text>我的积分</text>
					</view>
					<view class="right">
						<text>{{credits}}积分</text>
						<uni-icons type="right" size="14" color="#9498A0"></uni-icons>
					</view>
				</view>
				<view class="list-item" @click="goTo('./deliver/deliver')">
					<view class="left">
						<image
							src="https://staticfile-yj.obs.myhuaweicloud.com/%E6%88%91%E7%9A%84%E5%8F%91%E8%B4%A7.png"
							mode="widthFix"></image>
						<text>我的发货</text>
					</view>
					<view class="right">
						<uni-icons type="right" size="14" color="#9498A0"></uni-icons>
					</view>
				</view>
				<view class="list-item" @click="goTo('./deliver/deliver')">
					<view class="left">
						<image
							src="https://staticfile-yj.obs.myhuaweicloud.com/%E6%88%91%E7%9A%84%E6%94%B6%E8%B4%A7.png"
							mode="widthFix"></image>
						<text>我的收货</text>
					</view>
					<view class="right">
						<uni-icons type="right" size="14" color="#9498A0"></uni-icons>
					</view>
				</view>
				<view class="list-item" @click="goTo('./setting/setting')">
					<view class="left">
						<image
							src="https://staticfile-yj.obs.myhuaweicloud.com/%E7%B3%BB%E7%BB%9F%E8%AE%BE%E7%BD%AE.png"
							mode="widthFix"></image>
						<text>系统设置</text>
					</view>
					<view class="right">
						<uni-icons type="right" size="14" color="#9498A0"></uni-icons>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		baseurl,
		queryMyTotalScore,
		countCollection,
		numberOfCollections,
		queryCurrentAccount,

	} from "@/api/user.js"
	let imgUrl = baseurl + "/nb-as/1.0.1/FileService/previewFile?fileId="
	export default {
		data() {
			return {
				userInfo:{},
				roleName:'',
				credits:'',
				collectNum:{},
				imgUrl,
			}
		},
		onLoad() {
			//this.userInfo = uni.getStorageSync('userInfo')
			// this.queryCurrentAccount({});
			// countCollection().then((res)=>{
			// 	this.collectNum = res.returnObj;
			// 	let farmNum = this.collectNum.farmSeek + this.collectNum.farmWork
			// 	this.$set(this.collectNum,'farm',farmNum)
			// })
			// this.queryMyTotalScore()
		},
		onShow() {			
			countCollection().then((res)=>{
				this.collectNum = res.returnObj;
				let farmNum = this.collectNum.farmSeek + this.collectNum.farmWork
				this.$set(this.collectNum,'farm',farmNum)
				this.queryCurrentAccount({});
				this.queryMyTotalScore()
			})
		},
		onPullDownRefresh(){
			this.queryCurrentAccount({});
			this.queryMyTotalScore()
			countCollection().then((res)=>{
				this.collectNum = res.returnObj;
				let farmNum = this.collectNum.farmSeek + this.collectNum.farmWork
				this.$set(this.collectNum,'farm',farmNum)
			})
			uni.stopPullDownRefresh();
		},
		methods: {
			async queryMyTotalScore(){
				const res = await queryMyTotalScore();
				if(res.success){
					this.credits = res.returnObj
				}
			},
			async queryCurrentAccount(options){
				const res = await queryCurrentAccount(options);
				this.userInfo = res.returnObj;
			},
			goTo(e) {
				var url = e;
				uni.navigateTo({
					url: url
				})
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-image: url("https://staticfile-yj.obs.cn-north-4.myhuaweicloud.com/my-bg.png");
		background-repeat: no-repeat;
		background-size: 100% auto;
	}

	.head {
		padding: 280rpx 0 0 30rpx;
		display: flex;
		flex-flow: row nowrap;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 20px;

		.head-left {
			display: flex;
			flex-flow: row nowrap;
			justify-content: space-between;
			align-items: center;

			.info {
				margin-left: 20rpx;

				.name {
					display: block;
					color: #ffffff;
					font-size: 40rpx;
					font-weight: 500;
					height: 28px;
					line-height: 28px;
				}
			}
		}
	}

	.head .head-left .figure image {
		width: 68px;
		height: 68px;
		border-radius: 100%;
	}

	.head .head-left .info .credential image {
		width: 148rpx;
		height: 22px;
		margin-top: 10px;
	}

	.head-right text {
		background-image: linear-gradient(289.18deg, #22AFFF 0%, #00C3CF 100%);
		;
		border-radius: 18px 0px 0px 18px;
		width: 144rpx;
		padding: 8px 24rpx;
		color: #ffffff;
		font-size: 24rpx;
	}

	.collect {
		background-color: #ffffff;
		padding: 30rpx;
		border-radius: 12px 12px 0 0;

		.title {
			font-weight: 500;
			font-size: 32rpx;
			line-height: 24px;
			height: 24px;
		}

		.collect-con {
			display: flex;
			flex-flow: row nowrap;
			justify-content: space-around;
			align-items: center;
			margin-top: 30rpx;

			.num {
				font-weight: 500;
				font-size: 40rpx;
				line-height: 28px;
			}

			.name {
				font-size: 24rpx;
				line-height: 20px;
				color: #9498A0;
			}
		}
	}

	.collect-con .item text {
		display: block;
		text-align: center;
	}

	.mine-list {
		background-color: #ffffff;
		border-radius: 12px;
		margin-top: 15px;
		padding: 15px 30rpx;

		.list-item {
			display: flex;
			flex-flow: row nowrap;
			justify-content: space-between;
			align-items: center;
			margin-bottom: 15px;

			.left {
				display: flex;
				flex-flow: row nowrap;
				justify-content: flex-start;
				align-items: center;
			}

			.right {
				color: #00B5DD;
				font-size: 28rpx;
			}
		}
	}

	.list-item .left image {
		width: 20px;
		height: 20px;
		margin-right: 10px;
	}

	.list-item .left text {
		font-size: 28rpx;
		color: #283241;
	}
</style>